<?php
/**
 * Directory list to .CSV 
 *  
 * @author $Author: davidjimenez75 $:
 * @package dir2csv
 * @version $Id: index.php 44 2009-07-13 21:33:26Z davidjimenez75 $:
 * 
 * @todo
 * 
 * @internal $Rev: 44 $:
 * 
 **/
require_once("config.php");
echo '<font style="font-family:courier;font-size:xx-small;">'; 

$a_output=recur_dir("."); 

// UNA DIMENSION 
while(list ($key,$val) = each ($a_output)){  

$a_ignored=array("index.php","index.php~","config.php","config.php~",".svn");

if ( !in_array($val[name],$a_ignored) ) 
   if ($val[kind]=="dir")
   {
     	 $a_ficheros [] = trocear($val[name]. '--(DIR)');  
   }else{	
    	 $a_ficheros [] = trocear($val[name]. '--(FILE)');  
  }
  
  
} // while
echo nl2br($output);

sort($a_ficheros);
while(list ($key,$val) = each ($a_ficheros))
{  
$output.= $val."\r\n";
}

echo nl2br($output);

echo '</font>';

if (__DIR2CSV_DEBUG__) echo '<hr><h1>DEBUG</h1><pre>'.print_r($a_output).'</pre><hr>';

if (__DIR2CSV_DEBUG__)
{
$changelog .= "<h1>".__DIR2CSV_TITLE__."  changelog</h1>\r\n";
$changelog .= "yyyy-mm-dd;hhmm;Rev\r\n";
$changelog .= "----------;----;---\r\n";
$changelog .= "2008-02-28;2100;40;Primera branch como DATE--HOUR\r\n";
$changelog .= "2008-02-28;1620;39;Logro mezclar todo en el trunk :)\r\n";
$changelog .= "2008-02-28;1620;37;Creada como Branch\r\n";
$changelog .= "2008-02-28;1620;34\r\n";
$changelog .= "2008-02-28;1620;31?\r\n";
$changelog .= "2008-02-28;1537;26\r\n";
$changelog .= "2008-02-28;2434;25\r\n";
$changelog .= "2008-02-28;2431;24\r\n";
$changelog .= "2008-02-28;2428;23\r\n";
$changelog .= "2008-02-28;2423;22\r\n";
$changelog .= "2008-02-28;2422;19\r\n";
$changelog .= "2008-02-28;2415;18\r\n";
$changelog .= "2008-02-28;2408;17\r\n";
$changelog .= "2008-02-27;2355;\r\n";
$changelog .= "2008-02-27;2355;\r\n";
echo nl2br($changelog);
}


function recur_dir($dir) 
{ 
    $dirlist = opendir($dir); 
    while ($file = readdir ($dirlist)) 
    { 
        if ($file != '.' && $file != '..') 
        { 
            $newpath = $dir.'/'.$file; 
            $level = explode('/',$newpath); 
            if (is_dir($newpath)) 
            { 
                $mod_array[] = array( 
                        'level'=>count($level)-1, 
                        'path'=>$newpath, 
                        'name'=>end($level), 
                        'kind'=>'dir', 
                        'mod_time'=>filemtime($newpath), 
                        'content'=>recur_dir($newpath)); 
            }else{ 

                $mod_array[] = array( 
                        'level'=>count($level)-1, 
                        'path'=>$newpath, 
                        'name'=>end($level), 
                        'kind'=>'file', 
                        'mod_time'=>filemtime($newpath), 
                        'size'=>filesize($newpath)); 
           } 
        } 
    } 
    closedir($dirlist); 
    return $mod_array; 
} 

function trocear($filename)
{
    $a_output=split(__DIR2CSV_SEPARATOR__, $filename);
    $output="";    
  
    //TODO: Bucle segun longitud
	if (sizeof($a_output)>>1)
	{
		    for ($a = 0,$b = sizeof($a_output);$a < $b;$a++)
		    $output.= trim($a_output[$a].';');
			 return($output);    
    }else{
   		 return($filename);
    }
 
    
}




?>